﻿using System;
using System.Web.Mvc;
using OASys.Biz.BizAccess;
using OASys.Enum;
using OASys.Web.Areas.ModuleSys.Models;
using OASys.Web.Base;
using Project.Common;
using Project.Web.Base;
using Project.Web.Base.Utility;
namespace OASys.Web.Areas.ModuleSys.Controllers
{
	/// <summary>
	/// 
	/// </summary>
    public class SysMenuManageController : BaseController
    {

        private BizSysMenu bizSysMenu;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult Index(ModelSysMenuManageIndex model)
        {
            model.RetriveData();
            return View(model);
        }

        /// <summary>
        /// 创建或修改菜单
        /// </summary>
        public ActionResult Create(ModelSysMenuManageCreate model)
        {
            ViewBag.PageState = model.PageState;
            model.RetriveData();
            return View(model);
        }

        /// <summary>
        /// 创建或修改菜单
        /// </summary>
        [HttpPost]
        public ActionResult Create(ModelSysMenuManageCreate model, FormCollection collection)
        {
            try
            {
                model.Save();
                var option = DialogOption.GetDefaultInstance();
                option.IsRefreshParentAsynchronous = false;
                return Content(WebTools.ScriptCloseDialog(option));
            }
            catch
            {
                Error = OASys.Resources.Properties.Resources.M00002E;
                model.RetriveData();
                return View(model);
            }
        }

        /// <summary>
        /// 根据主键删除
        /// </summary>
        [HttpPost]
        public ActionResult Delete(Guid id)
        {
            JsonResult jsresult = new JsonResult();
            jsresult.ContentType = Consts.CONTENT_TYPE;
            jsresult.Data = new { result = bizSysMenu.DeleteSysMenuByID(id) };
            return jsresult;
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        [HttpPost]
		public ActionResult DeleteBatch(string[] checkboxItem, string RetUrl)
        {
            try
            {
                for (int i = 0; i < checkboxItem.Length; i++)
                {
                    if (checkboxItem[i].ToLower() == EnumTrueOrFalse.False.ToString().ToLower())
                        continue;
                    bizSysMenu.DeleteByID(checkboxItem[i], NHibernate.NHibernateUtil.String);
                }
				return Redirect(RetUrl);
            }
            catch
            {
                Error = OASys.Resources.Properties.Resources.M00002E;
                return Redirect(RetUrl);
            }
        }

        /// <summary>
        /// 验证菜单名是否存在
        /// </summary>
        public ActionResult RemoteCheckMenuName(ModelSysMenuManageCreate model)
        {
            return false ? Json(false, JsonRequestBehavior.AllowGet) : Json(true, JsonRequestBehavior.AllowGet);
        }
    }

}
